package com.cg.controller;

import com.cg.common.PageResult;
import com.cg.common.Result;
import com.cg.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/job")
public class JobController {

    @Autowired
    private JobService jobService;


    @GetMapping("/keywords")
    public Result getKeywords(){
        return Result.success(jobService.getKeywords());
    }

    @GetMapping("/list")
    public Result listJobs(@RequestParam(required = false) String city,
                           @RequestParam(required = false) Integer expectMinSalary,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "24") Integer pageSize){
        PageResult<Map<String,Object>> page = jobService.listJobs(city, expectMinSalary, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 按岗位类型分页（front/java/python/...），type 对应具体爬虫表
     * 取值：java/back/c/front/go/javascript/nodejs/operations/python/test/web/all
     */
    @GetMapping("/listByType")
    public Result listJobsByType(@RequestParam String type,
                                 @RequestParam(required = false) String city,
                                 @RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "24") Integer pageSize){
        PageResult<Map<String,Object>> page = jobService.listJobsByType(type, city, null, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/citySalaryDistribution")
    public Result citySalaryDistribution(@RequestParam(required = false) String city){
        return Result.success(jobService.getCitySalaryDistribution(city));
    }

    @GetMapping("/pmTopSkills")
    public Result pmTopSkills(){
        return Result.success(jobService.getProductManagerTopSkills());
    }

    
}


